﻿Imports mshtml
Imports System.Data  
Imports System.Collections.ObjectModel  


Class CMValmer

Private datos As datatable 


Private  negocioValmer As New CValmerServicio



Public Sub New()             
 InitializeComponent()
 CargarParametrosMasiva()
 InitializeComponent()        
 InicializarFechaHora () 

 Mouse.OverrideCursor = Nothing   
         
End Sub



Private Sub imgConsultarDecalog_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgConsultarDecalog.MouseLeftButtonUp


'0) limpiar campos

LimpiarCamposConsulta()
LimpiarCamposCalculo ()


'1) Buscar en Decalog instrumentos similares y obtener el número de instrumento.

 Dim app     As Application = DirectCast (Application.Current,Application  )
 Dim ventana As MainWindow  = app.Windows(0)
         
 ventana.paramEntreVentanasValmer.instrumento = Me.txtInstrumento.Text

 Dim ventanaPopInst As New CIntrumentosValmer ()

 ventanaPopInst.Owner = app.Windows(0)
 AplicarEfecto (app.Windows(0))
 ventanaPopInst.ShowDialog 
 QuitarEfecto(app.Windows(0))

 If ventanaPopInst.DialogResult =False then     
    Mouse.OverrideCursor = Nothing 
    Exit sub
 End If



 Me.txtInstrumento.Text     =  ventana.paramEntreVentanasValmer.instrumento 
 
If ventana.paramEntreVentanasValmer.numero  > 0 then 
    Me.txtNumInstrumento.Text  =  ventana.paramEntreVentanasValmer.numero  
 Else
    Me.txtNumInstrumento.Text  = ""
 End If



'Comienza la Busqueda en el sito Web de Valmer

Mouse.OverrideCursor = Cursors.Wait  

 Dim InstrumentoSeparado() As String 
 Dim parametros            As CAccesoHTML.ParamConsultaDatosValmer  
 Dim dt                    as DataTable 


 

 InstrumentoSeparado =  Me.txtInstrumento.Text.Split ("_")  

 If InstrumentoSeparado.Length = 3 then 
    Me.txtTipoValor.Text = InstrumentoSeparado(0) 
    Me.txtEmisora.Text   = InstrumentoSeparado(1) 
    Me.txtSerie.Text     = InstrumentoSeparado(2)
   

    With parametros
         .tv           = Me.txtTipoValor.Text
         .emisora      = Me.txtEmisora.Text
         .serie        = Me.txtSerie.Text
         .radio        = "precio"
         .tipoInstDec  = negocioValmer.ObtenerTipoInstrumentoDecalog (.tv)
         .fecha        = CServiciosMacrosSyBaseDB.FechaHoyDB ().ToString("yyyy-MM-dd")  

         .numRegLayout = "18"
         .numColLayout = "2"
    End With
        
    dt = negocioValmer.ObtenerTablaDatos (parametros)
   
    If dt is Nothing then 
       Mouse.OverrideCursor = Nothing 
       Exit Sub 
    End If


    me.txtSobreTasa.Text           = dt(0)(1)
    me.txtTasaYTM.Text             = dt(1)(1)   
    me.txtTasaCupon.Text           = dt(2)(1)
    me.txtTasaMercado.Text         = dt(3)(1)
    me.txtISR.Text                 = dt(4)(1)
    me.txtUDI.Text                 = dt(5)(1)
    me.txtUSD.Text                 = dt(6)(1)
    me.txtTasaDesc.Text            = dt(7)(1)
    me.lblVPrima.Content           = dt(8)(1)
    me.lblVFecIniCupon.Content     = dt(9)(1)
    me.lblVFecVtoLegal.Content     = dt(10)(1)
    me.lblVFecVtoEstimada.Content  = dt(11)(1)
    me.lblVDiasvenc.Content        = dt(12)(1)
    me.lblVValorNom.Content        = dt(13)(1)
    me.lblVPCV.Content             = dt(14)(1)
    me.lblVPC.Content              = dt(15)(1)
    me.lblVDTCV.Content            = dt(16)(1)
    me.lblVCuponesPend.Content     = dt(17)(1)

 End If



 Mouse.OverrideCursor = Nothing 

End Sub

Private Sub imgCalcular_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgCalcular.MouseLeftButtonUp

    
    
 Mouse.OverrideCursor = Cursors.Wait        
    
 
    LimpiarCamposCalculo ()


    Dim tablasHTMLaVB   As New List(Of DataTable)   
    Dim parametrosCalc As CAccesoHTML.ParamFlujosValmer 
   

  With  parametrosCalc

       .tv          = Me.txtTipoValor.Text
       .emisora     = Me.txtEmisora.Text 
       .serie       = Me.txtSerie.Text
       .calcula     = "Calcular"
       .radio       = "precio"
       .tipoInstDec = negocioValmer.ObtenerTipoInstrumentoDecalog (.tv)
       .fecha       = CServiciosMacrosSyBaseDB.FechaHoyDB ().ToString("yyyy-MM-dd")
       .pEdit       = ""

       .sobretasa          = me.txtSobreTasa.Text.Trim   
       .tasaRendimiento    = me.txtTasaYTM.Text.Trim    
       .tasaCupon          = me.txtTasaCupon.Text.Trim   
       .tasaMercado        = me.txtTasaMercado.Text.Trim 
       .isr                = me.txtISR.Text.Trim         
       .tipoCambioUDI      = me.txtUDI.Text.Trim         
       .tipoCambioUSD      = me.txtUSD.Text.Trim         
       .tasaDescuento      = me.txtTasaDesc.Text.Trim    

  End With


  tablasHTMLaVB =   negocioValmer.ObtenerTablasCalculos (parametrosCalc)
  
  if tablasHTMLaVB is Nothing  then 
      Mouse.OverrideCursor = Nothing 
     'PENDIENTE
     Exit Sub 
  End If

  'TABLA DE VALUACION     

   Me.lblVTipoIns.Content    = tablasHTMLaVB(0)(0)(1)
   Me.lblVTasaRef.Content    = tablasHTMLaVB(0)(1)(1)
   Me.lblVCurvaDesc.Content  = tablasHTMLaVB(0)(2)(1)
   Me.lblVMoneda.Content     = tablasHTMLaVB(0)(3)(1)

  'TABLA DE FORMULA ESTÁNDARIZADA

   Me.txtVPrecioSucioTR.text    =  tablasHTMLaVB(1)(2)(0)
   Me.txtVPrecioLimpioTR.text   =  tablasHTMLaVB(1)(2)(1)
   Me.txtVInteresesTR.text      =  tablasHTMLaVB(1)(2)(2)

  'TABLA DE FORMULA FLUJOS

   Me.txtVPrecioSucioTI.text    =  tablasHTMLaVB(2)(2)(0)
   Me.txtVPrecioLimpioTI.text   =  tablasHTMLaVB(2)(2)(1)
   Me.txtVInteresesTI.text      =  tablasHTMLaVB(2)(2)(2)


  'TABLA DE FLUJOS

   Me.grdFlujos.ItemsSource =  negocioValmer.ObtenerFlujosComoLista(tablasHTMLaVB(3),3,Me.lblVTipoIns.Content)
                                

   Me.grdFlujos.Items.Refresh ()

 
 Mouse.OverrideCursor = Nothing 

End Sub

Private Sub AplicarEfecto (ByRef ventanaBack As Window )
 Dim oBlur As New System.Windows.Media.Effects.BlurEffect ()    
 oBlur.Radius = 7
 ventanaBack.Effect = oBlur 
End Sub 

Private Sub QuitarEfecto (ByRef ventanaBack As Window )
 ventanaBack.Effect = Nothing 
End Sub 

Private Sub Page_Unloaded(ByVal sender As System.Object , ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Unloaded

 Dim app     As Application = DirectCast (Application.Current,Application  )
 Dim ventana As MainWindow  = app.Windows(0)
          
 ventana.paramEntreVentanasValmer.instrumento = ""
 ventana.paramEntreVentanasValmer.numero  = 0

End Sub

Private Sub imgCargaDecalog_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgCargaDecalog.MouseLeftButtonUp


 
  Dim alertasResp        As Integer 
  Dim sMsgError          As String = ""


  Dim razonInstrumValmer As new CRazonInstrumento(0,"",0,0)
  Dim flujos             As New List(Of CFlujoValmer)    


  alertasResp = MessageBox.Show("¿Esta seguro de que quiere cargar el archivo?","Carga en Decalog",MessageBoxButton.YesNo,MessageBoxImage.Question )   


  If alertasResp = System.Windows.MessageBoxResult.No  then     
     Exit sub
  End If

  'Validar número de instrumento Decalog
   
   If Not IsNumeric (txtNumInstrumento.Text) then       
      MessageBox.Show ("Sin número de instrumento no se puede realizar la carga.","Carga Decalog",MessageBoxButton.OK,MessageBoxImage.Information)                    
      Exit sub
   End If

  'Validar que existan flujos a procesar

   If Me.grdFlujos.Items.Count <= 0 then    
      MessageBox.Show ("No existen datos a procesar (Tabla Flujos).","Carga Decalog",MessageBoxButton.OK,MessageBoxImage.Information)                      
      Exit sub
   End If

   'Se valida el tipo de instrumento en la tabla de valuación
  if lblVTipoIns.Content.ToString.Trim.Equals("") then 
     MessageBox.Show ("No existen datos a procesar.","Carga Decalog",MessageBoxButton.OK,MessageBoxImage.Information)                      
     Exit sub
  End If
 

   If alertasResp = System.Windows.MessageBoxResult.Yes and negocioValmer.Check (razonInstrumValmer,lblVTipoIns.Content.ToString, Convert.ToInt32(txtNumInstrumento.Text),sMsgError) = True then 
      
      MessageBox.Show ("Recuerde cambiar el current face del instrumento en Decalog si fuese necesario","Carga Decalog",MessageBoxButton.OK,MessageBoxImage.Information) 
         
      'Aqui va la generación del archivo
       flujos = Me.grdFlujos.ItemsSource
       
        sMsgError = ""


       If negocioValmer.ConstruirArchivoValmerDecalog(Convert.ToInt32 (Me.txtNumInstrumento.Text),flujos,razonInstrumValmer, me.lblVMoneda.Content.ToString(), sMsgError) = True  then
          negocioValmer.EjecutarProceso ()
          MessageBox.Show ("La carga a Decalog fue exitosa","Carga Decalog", MessageBoxButton.OK,MessageBoxImage.Information)         
       Else 
          MessageBox.Show ("La carga a Decalog no fue exitosa debido a: " & sMsgError,"Carga Decalog", MessageBoxButton.OK,MessageBoxImage.Error)         
       End If
       

   Else 
     If Not sMsgError.Trim.Equals("") then 
         MessageBox.Show (sMsgError ,"Carga Decalog",MessageBoxButton.OK,MessageBoxImage.Exclamation ) 
     end if
   End If


End Sub

Public Sub LimpiarCamposConsulta()

 

'********DATOS********

me.txtSobreTasa.Text           = ""
me.txtTasaYTM.Text             = ""
me.txtTasaCupon.Text           = ""
me.txtTasaMercado.Text         = ""
me.txtISR.Text                 = ""
me.txtUDI.Text                 = ""
me.txtUSD.Text                 = ""
me.txtTasaDesc.Text            = ""
me.lblVPrima.Content           = ""
me.lblVFecIniCupon.Content     = ""
me.lblVFecVtoLegal.Content     = ""
me.lblVFecVtoEstimada.Content  = ""
me.lblVDiasvenc.Content        = ""
me.lblVValorNom.Content        = ""
me.lblVPCV.Content             = ""
me.lblVPC.Content              = ""
me.lblVDTCV.Content            = ""
me.lblVCuponesPend.Content     = ""


   'PARTES DEL INSTRUMENTO
   Me.txtTipoValor.Text = ""
   Me.txtEmisora.Text   = ""
   Me.txtSerie.Text     = ""


End Sub

Public Sub LimpiarCamposCalculo()

 'TABLA DE VALUACION     

   Me.lblVTipoIns.Content    = ""
   Me.lblVTasaRef.Content    = ""
   Me.lblVCurvaDesc.Content  = ""
   Me.lblVMoneda.Content     = ""

  'TABLA DE FORMULA ESTÁNDARIZADA

   Me.txtVPrecioSucioTR.text    =  ""
   Me.txtVPrecioLimpioTR.text   =  ""
   Me.txtVInteresesTR.text      =  ""

  'TABLA DE FORMULA FLUJOS

   Me.txtVPrecioSucioTI.text    =  ""
   Me.txtVPrecioLimpioTI.text   =  ""
   Me.txtVInteresesTI.text      =  ""


  'TABLA DE FLUJOS

   Me.grdFlujos.ItemsSource = Nothing 
   Me.grdFlujos.Items.Refresh ()



End Sub



'************************************MASIVA***********************************************************************+++

Private  GrupoEnEdicionSAL  As CTInstrumentosValmerBatch 
Private  SecTypeEnEdicionSAL  As CTInstrumentosValmerBatch 
Private  InstrumentoEnEdicionSAL  As CTInstrumentosValmerBatch 



Private Sub grdGrupo_BeginningEdit(ByVal sender As System.Object , ByVal e As System.Windows.Controls.DataGridBeginningEditEventArgs) Handles grdGrupo.BeginningEdit
   GrupoEnEdicionSAL = grdGrupo.CurrentItem  
End Sub

Private Sub grdGrupo_CellEditEnding(ByVal sender As System.Object , ByVal e As System.Windows.Controls.DataGridCellEditEndingEventArgs) Handles grdGrupo.CellEditEnding          
   
     Dim grupos As ObservableCollection(Of CTInstrumentosValmerBatch ) = grdGrupo.ItemsSource
     Dim grupoActual As CTInstrumentosValmerBatch 
     'Dim grupoCambio As New CTInstrumentosValmerBatch()
                                  
        
        Select Case e.EditAction

            Case DataGridEditAction.Commit

              If not sender.CurrentItem is Nothing then

                    Dim txtContenidoCelda As Object   = grdGrupo.Columns(0).GetCellContent(grdGrupo.CurrentItem)         
                    grupoActual = TryCast(grdGrupo.CurrentCell.Item, CTInstrumentosValmerBatch)

                    If grupoActual.Equals (grupoEnEdicionSAL) = False then 
                         CType(sender,DataGrid).CancelEdit (DataGridEditingUnit.Cell)  
                    End If
                                        

                    grupoActual.Grupo  = txtContenidoCelda.Text 
                                        
                    

                    If grupoActual.EsEditableNuevo Then
                        Try
                           grupoActual.EsEditableNuevo = False                            
                        Catch ex As Exception                           
                            CType(sender,DataGrid).CancelEdit (DataGridEditingUnit.Cell)
                        End Try                                                    
                    End If
               else
                  CType(sender,DataGrid).CancelEdit (DataGridEditingUnit.Cell)  
               End If

            Case DataGridEditAction.Cancel
                 
                grupoActual   = TryCast(grdGrupo.Items(grdGrupo.Items.Count - 1),CTInstrumentosValmerBatch )
                
                if grupoActual.EsEditableNuevo then 
                   grupos.Remove(grupoActual)                    
                   grdGrupo.UpdateLayout()                          
                End If


        End Select

        GrupoEnEdicionSAL = Nothing 

End Sub

Private Sub imgAgregarGrupo_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgAgregarGrupo.MouseLeftButtonUp
  Dim regNvo As new CTInstrumentosValmerBatch("Escriba aquí...",True)
  
  Dim lstGrupos As new ObservableCollection (Of CTInstrumentosValmerBatch)
          
   grdGrupo.UnselectAll ()
   

   'Esta condición es necesaria dado que no existe una lista de items previa
   If Not grdGrupo.ItemsSource is Nothing   then 
      lstGrupos = grdGrupo.ItemsSource    
   End If
   
   lstGrupos.Add (regNvo)             
   grdGrupo.ItemsSource = lstGrupos
   grdGrupo.ScrollIntoView (grdGrupo.Items(grdGrupo.Items.Count-1))
   
   grdGrupo.UpdateLayout()
  

  Dim celda As DataGridCell = ObtenerCelda (grdGrupo,grdGrupo.Items.Count-1,0)
  If Not celda is Nothing 
    celda.Focus()
    grdGrupo.BeginEdit () 
    celda.IsSelected = true    
  End If
End Sub

Private Sub imgEliminarGrupo_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgEliminarGrupo.MouseLeftButtonUp
 Dim grupos As ObservableCollection(Of CTInstrumentosValmerBatch  ) = grdGrupo.ItemsSource
 Dim grupoElim As new ObservableCollection(Of CTInstrumentosValmerBatch  )
 Dim grupoNoElim As new ObservableCollection(Of CTInstrumentosValmerBatch  )

 Dim nomGruposNoElim As new System.Text.StringBuilder ()

 
  If grdGrupo.SelectedCells.Count > 0 then
     If MessageBox.Show ("Esta seguro que desea eliminar las celdas seleccionadas","Eliminar grupos",MessageBoxButton.OKCancel,MessageBoxImage.Question ) =MessageBoxResult.OK then 
     

     
     For Each celda As DataGridCellInfo In grdGrupo.SelectedCells                                
        grupoElim.Add (CType(celda.Item,CTInstrumentosValmerBatch))       
     Next

     For Each grupo As CTInstrumentosValmerBatch  In grupoElim         
         grupos.Remove(grupo)                                                 
     Next

  End If
  End If

 grdGrupo.UpdateLayout ()


 If grupoNoElim.Count > 0 then             
    For Each grupo As  CTInstrumentosValmerBatch   In grupoNoElim 
        nomgruposNoElim.Append (grupo.Grupo )
         nomgruposNoElim.Append (", ")
    Next

    MessageBox.Show ("Los Grupos: " & nomgruposNoElim.ToString () & " no pudieron ser eliminados.", "Eliminar grupos",MessageBoxButton.OK,MessageBoxImage.Exclamation ) 

 End If


End Sub





Private Sub grdSecType_BeginningEdit(ByVal sender As System.Object , ByVal e As System.Windows.Controls.DataGridBeginningEditEventArgs) Handles grdSecType.BeginningEdit
   SecTypeEnEdicionSAL = grdSecType.CurrentItem           
End Sub

Private Sub grdSecType_CellEditEnding(ByVal sender As System.Object , ByVal e As System.Windows.Controls.DataGridCellEditEndingEventArgs) Handles grdSecType.CellEditEnding          
   
     Dim tipos As ObservableCollection(Of CTInstrumentosValmerBatch ) = grdSecType.ItemsSource
     Dim tipoActual As CTInstrumentosValmerBatch 
     
                                  
        
        Select Case e.EditAction

            Case DataGridEditAction.Commit

              If not sender.CurrentItem is Nothing then

                    Dim txtContenidoCelda As Object   = grdSecType.Columns(0).GetCellContent(grdSecType.CurrentItem)         
                    tipoActual = TryCast(grdSecType.CurrentCell.Item, CTInstrumentosValmerBatch)

                    If tipoActual.Equals (SecTypeEnEdicionSAL) = False then 
                         CType(sender,DataGrid).CancelEdit (DataGridEditingUnit.Cell)  
                    End If
                         
               
        

                    If IsNumeric (txtContenidoCelda.Text) then 
                       tipoActual.Tipo   = txtContenidoCelda.Text
                          If tipoActual.EsEditableNuevo Then                                                
                             tipoActual.EsEditableNuevo = False                                                                                                
                          End If

                    else
                        MessageBox.Show ("El valor debe ser numérico")                                                  
                        CType(sender,DataGrid).CancelEdit (DataGridEditingUnit.Cell)
                                                                          
                    End If
                                                                         
                  
               else
                  CType(sender,DataGrid).CancelEdit (DataGridEditingUnit.Cell)  
               End If

            Case DataGridEditAction.Cancel
                 
                tipoActual   = TryCast(grdSecType.Items(grdSecType.Items.Count - 1),CTInstrumentosValmerBatch )
                
                if tipoActual.EsEditableNuevo then 
                   tipos.Remove(tipoActual)                    
                   grdSecType.UpdateLayout()                          
                End If


        End Select

        SecTypeEnEdicionSAL = Nothing 

End Sub

Private Sub imgAgregarSecTipo_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgAgregarSecTipo.MouseLeftButtonUp
  Dim regNvo As new CTInstrumentosValmerBatch(True)
  
  Dim lstTipos As new ObservableCollection (Of CTInstrumentosValmerBatch)
          
   grdSecType.UnselectAll ()
   

   'Esta condición es necesaria dado que no existe una lista de items previa
   If Not grdSecType.ItemsSource is Nothing   then 
      lstTipos = grdSecType.ItemsSource    
   End If
   
   lstTipos.Add (regNvo)             
   grdSecType.ItemsSource = lstTipos 
   grdSecType.ScrollIntoView (grdSecType.Items(grdSecType.Items.Count-1))
   
   grdSecType.UpdateLayout()
  

  Dim celda As DataGridCell = ObtenerCelda (grdSecType,grdSecType.Items.Count-1,0)
  If Not celda is Nothing 
    celda.Focus()
    grdSecType.BeginEdit () 
    celda.IsSelected = true    
  End If
End Sub

Private Sub imgEliminarSecTipo_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgEliminarSecTipo.MouseLeftButtonUp
 Dim tipos As ObservableCollection(Of CTInstrumentosValmerBatch  ) = grdSecType.ItemsSource
 Dim tipoElim As new ObservableCollection(Of CTInstrumentosValmerBatch  )
 Dim tipoNoElim As new ObservableCollection(Of CTInstrumentosValmerBatch  )

 Dim nomTiposNoElim As new System.Text.StringBuilder ()

 
  If grdSecType.SelectedCells.Count > 0 then
     If MessageBox.Show ("Esta seguro que desea eliminar las celdas seleccionadas","Eliminar Tipos",MessageBoxButton.OKCancel,MessageBoxImage.Question ) =MessageBoxResult.OK then 
     

     
     For Each celda As DataGridCellInfo In grdSecType.SelectedCells                                
        tipoElim.Add (CType(celda.Item,CTInstrumentosValmerBatch))       
     Next

     For Each tipo As CTInstrumentosValmerBatch  In tipoElim         
         tipos.Remove(tipo)                                                 
     Next

  End If
  End If

 grdSecType.UpdateLayout ()


 If tipoNoElim.Count > 0 then             
    For Each tipo As  CTInstrumentosValmerBatch   In tipoNoElim 
        nomTiposNoElim.Append (tipo.Tipo.ToString () )
         nomTiposNoElim.Append (", ")
    Next

    MessageBox.Show ("Los tipos: " & nomTiposNoElim.ToString () & " no pudieron ser eliminados.", "Eliminar tipos",MessageBoxButton.OK,MessageBoxImage.Exclamation ) 

 End If


End Sub





Private Sub grdNumInstrumento_BeginningEdit(ByVal sender As System.Object , ByVal e As System.Windows.Controls.DataGridBeginningEditEventArgs) Handles grdNumInstrumento.BeginningEdit
   InstrumentoEnEdicionSAL = grdNumInstrumento.CurrentItem           
End Sub

Private Sub grdNumInstrumento_CellEditEnding(ByVal sender As System.Object , ByVal e As System.Windows.Controls.DataGridCellEditEndingEventArgs) Handles grdNumInstrumento.CellEditEnding          
   
     Dim instrumentos As ObservableCollection(Of CTInstrumentosValmerBatch ) = grdNumInstrumento.ItemsSource
     Dim instrumentoActual As CTInstrumentosValmerBatch 
     
                                          
        Select Case e.EditAction

            Case DataGridEditAction.Commit

              If not sender.CurrentItem is Nothing then

                    Dim txtContenidoCelda As Object   = grdNumInstrumento.Columns(0).GetCellContent(grdNumInstrumento.CurrentItem)         
                    instrumentoActual = TryCast(grdNumInstrumento.CurrentCell.Item, CTInstrumentosValmerBatch)

                    If instrumentoActual.Equals (InstrumentoEnEdicionSAL) = False then 
                         CType(sender,DataGrid).CancelEdit (DataGridEditingUnit.Cell)  
                    End If
                                                           

                    If IsNumeric (txtContenidoCelda.Text) then 
                       instrumentoActual.NumInstrumento    = txtContenidoCelda.Text                         
                          If instrumentoActual.EsEditableNuevo Then                                                
                             instrumentoActual.EsEditableNuevo = False                                                                                                
                          End If

                    else
                        MessageBox.Show ("El valor del número de instrumento debe ser numérico")                                                  
                        CType(sender,DataGrid).CancelEdit (DataGridEditingUnit.Cell)
                                                                          
                    End If
                                                                         
                  
               else
                  CType(sender,DataGrid).CancelEdit (DataGridEditingUnit.Cell)  
               End If

            Case DataGridEditAction.Cancel
                 
                instrumentoActual   = TryCast(grdNumInstrumento.Items(grdNumInstrumento.Items.Count - 1),CTInstrumentosValmerBatch )
                
                if instrumentoActual.EsEditableNuevo then 
                   instrumentos.Remove(instrumentoActual)                    
                   grdNumInstrumento.UpdateLayout()                          
                End If


        End Select

        InstrumentoEnEdicionSAL = Nothing 

End Sub

Private Sub imgAgregarNumInsto_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgAgregarNumInsto.MouseLeftButtonUp
  Dim regNvo As new CTInstrumentosValmerBatch(True)
  
  Dim lstTipos As new ObservableCollection (Of CTInstrumentosValmerBatch)
          
   grdNumInstrumento.UnselectAll ()
   

   'Esta condición es necesaria dado que no existe una lista de items previa
   If Not grdNumInstrumento.ItemsSource is Nothing   then 
      lstTipos = grdNumInstrumento.ItemsSource    
   End If
   
   lstTipos.Add (regNvo)             
   grdNumInstrumento.ItemsSource = lstTipos 
   grdNumInstrumento.ScrollIntoView (grdNumInstrumento.Items(grdNumInstrumento.Items.Count-1))
   
   grdNumInstrumento.UpdateLayout()
  

  Dim celda As DataGridCell = ObtenerCelda (grdNumInstrumento,grdNumInstrumento.Items.Count-1,0)
  If Not celda is Nothing 
    celda.Focus()
    grdNumInstrumento.BeginEdit () 
    celda.IsSelected = true    
  End If
End Sub

Private Sub imgEliminarNumInsto_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgEliminarNumInsto.MouseLeftButtonUp
 Dim instrumentos As ObservableCollection(Of CTInstrumentosValmerBatch  ) = grdNumInstrumento.ItemsSource
 Dim instrumentoElim As new ObservableCollection(Of CTInstrumentosValmerBatch  )
 Dim instrumentoNoElim As new ObservableCollection(Of CTInstrumentosValmerBatch  )

 Dim numInstrumentosNoElim As new System.Text.StringBuilder ()

 
  If grdNumInstrumento.SelectedCells.Count > 0 then
     If MessageBox.Show ("Esta seguro que desea eliminar las celdas seleccionadas","Eliminar no. de instrumentos",MessageBoxButton.OKCancel,MessageBoxImage.Question ) =MessageBoxResult.OK then 
     

     
     For Each celda As DataGridCellInfo In grdNumInstrumento.SelectedCells                                
        instrumentoElim.Add (CType(celda.Item,CTInstrumentosValmerBatch))       
     Next

     For Each tipo As CTInstrumentosValmerBatch  In instrumentoElim         
         instrumentos.Remove(tipo)                                                 
     Next

  End If
  End If

 grdNumInstrumento.UpdateLayout ()


 If instrumentoNoElim.Count > 0 then             
    For Each numInst As  CTInstrumentosValmerBatch   In instrumentoNoElim 
        numInstrumentosNoElim.Append (numInst.NumInstrumento.ToString () )
        numInstrumentosNoElim.Append (", ")
    Next

    MessageBox.Show ("Los no. de instrumentos: " & instrumentoNoElim.ToString () & " no pudieron ser eliminados.", "Eliminar instrumentos",MessageBoxButton.OK,MessageBoxImage.Exclamation ) 

 End If


End Sub




Private Function  AgregarMenuContextualGrupo() As ContextMenu 
  Dim miMenuContextual     As New ContextMenu  
  Dim mnuPegar             As new System.Windows.Controls.MenuItem

 
   mnuPegar.Header = "Pegar"  
   miMenuContextual.Items.Add(mnuPegar)
   AddHandler mnuPegar.Click,AddressOf  mnuPegarGrupos_click 

 
   Return miMenuContextual 

End Function

Private Sub mnuPegarGrupos_click(sender As Object, e As RoutedEventArgs)
 Try
    pegarDatosGrupo(Me.grdGrupo)           
 Catch ex As Exception
            MessageBox.Show("Error TI500. " & ex.Message, "Pegar celdas", MessageBoxButton.OK, MessageBoxImage.Exclamation)
 End Try
   
End Sub 
 
Private Sub pegarDatosGrupo(ByRef gridDeDatos As DataGrid)


Dim lstAux As new   ObservableCollection (Of CTInstrumentosValmerBatch )  
Dim datos    As CDatosEnFormatoX 
Dim i        As Integer = 0
Dim nErrores As Integer = 0


  If Not gridDeDatos.ItemsSource is Nothing then 
    lstAux =  gridDeDatos.ItemsSource 
  End If
       
 datos = CUtileria.ObtenerDatosClipboard (vblf ,vbTab)

'1) Validaciones: obtener información del portapapeles

   If datos.Datos.length = 0 then 
      Exit sub
   End If


  If datos is Nothing then 
     MessageBox.Show ("No se pudo copiar los datos") 
     gridDeDatos.CancelEdit (DataGridEditingUnit.Cell)         
     Exit Sub 
  End If

'2) Validaciones: compatibilidad  
  

  For i = 0 to datos.NumeroRenglones - 1 
      Try
                       
          lstAux.Add (New CTInstrumentosValmerBatch(datos.Datos(i)(0).ToString.Trim,False))

      Catch ex As Exception
            nErrores += 1
      End Try           
  Next

  If nErrores > 0 then 
     If MessageBox.Show ("Existen " & nErrores  & " datos erróneos de " & datos.NumeroRenglones & ". ¿Desea pegar los datos correctos solamente?", "Copiado de grupos",MessageBoxButton.YesNo,MessageBoxImage.Question) = MessageBoxResult.Yes then 
        gridDeDatos.ItemsSource = lstAux  
     End If

   Else
       gridDeDatos.ItemsSource = lstAux  
  End If

  gridDeDatos.Items.Refresh () 

End Sub

Private Sub grdGrupo_MouseRightButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles grdGrupo.MouseRightButtonUp
     grdGrupo.ContextMenu =   AgregarMenuContextualGrupo() 
  
End Sub



Private Function  AgregarMenuContextualSecType() As ContextMenu 
  Dim miMenuContextual     As New ContextMenu  
  Dim mnuPegar             As new System.Windows.Controls.MenuItem

 
   mnuPegar.Header = "Pegar"  
   miMenuContextual.Items.Add(mnuPegar)
   AddHandler mnuPegar.Click,AddressOf  mnuPegarSecType_click 

 
   Return miMenuContextual 

End Function

Private Sub mnuPegarSecType_click(sender As Object, e As RoutedEventArgs)
 Try
    pegarDatosSecType(Me.grdSecType)           
 Catch ex As Exception
            MessageBox.Show("Error TI500. " & ex.Message, "Pegar celdas", MessageBoxButton.OK, MessageBoxImage.Exclamation)
 End Try
   
End Sub 
 
Private Sub pegarDatosSecType(ByRef gridDeDatos As DataGrid)


Dim lstAux As new   ObservableCollection (Of CTInstrumentosValmerBatch )  
Dim datos    As CDatosEnFormatoX 
Dim i        As Integer = 0
Dim nErrores As Integer = 0


Dim auxDato As String 


  If Not gridDeDatos.ItemsSource is Nothing then 
    lstAux =  gridDeDatos.ItemsSource 
  End If
       
 datos = CUtileria.ObtenerDatosClipboard (vblf ,vbTab)

'1) Validaciones: obtener información del portapapeles

   If datos.Datos.length = 0 then 
      Exit sub
   End If


  If datos is Nothing then 
     MessageBox.Show ("No se pudo copiar los datos") 
     gridDeDatos.CancelEdit (DataGridEditingUnit.Cell)         
     Exit Sub 
  End If

'2) Validaciones: compatibilidad  
  

  For i = 0 to datos.NumeroRenglones - 1 
      Try
                  
          auxDato = Convert.ToInt32 ( datos.Datos(i)(0).ToString.Trim)


          lstAux.Add (New CTInstrumentosValmerBatch( CTInstrumentosValmerBatch.TipoDeInstrumentoAProcesar.Dinamico,"",auxDato,-1,""))

      Catch ex As Exception
            nErrores += 1
      End Try           
  Next

  If nErrores > 0 then 
     If MessageBox.Show ("Existen " & nErrores  & " datos erróneos de " & datos.NumeroRenglones & ". ¿Desea pegar los datos correctos solamente?", "Copiado de Sec. Types",MessageBoxButton.YesNo,MessageBoxImage.Question) = MessageBoxResult.Yes then 
        gridDeDatos.ItemsSource = lstAux  
     End If

   Else
       gridDeDatos.ItemsSource = lstAux  
  End If

  gridDeDatos.Items.Refresh () 

End Sub

Private Sub grdSecType_MouseRightButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles grdSecType.MouseRightButtonUp
     grdSecType.ContextMenu =   AgregarMenuContextualSecType() 
  
End Sub



Private Function  AgregarMenuContextualInstrumento() As ContextMenu 
  Dim miMenuContextual     As New ContextMenu  
  Dim mnuPegar             As new System.Windows.Controls.MenuItem

 
   mnuPegar.Header = "Pegar"  
   miMenuContextual.Items.Add(mnuPegar)
   AddHandler mnuPegar.Click,AddressOf  mnuPegarInstrumento_click 

 
   Return miMenuContextual 

End Function

Private Sub mnuPegarInstrumento_click(sender As Object, e As RoutedEventArgs)
 Try
    pegarDatosInstrumento(Me.grdNumInstrumento)           
 Catch ex As Exception
            MessageBox.Show("Error TI500. " & ex.Message, "Pegar celdas", MessageBoxButton.OK, MessageBoxImage.Exclamation)
 End Try
   
End Sub 
 
Private Sub pegarDatosInstrumento(ByRef gridDeDatos As DataGrid)


Dim lstAux   As new   ObservableCollection (Of CTInstrumentosValmerBatch )  
Dim datos    As CDatosEnFormatoX 
Dim i        As Integer = 0
Dim nErrores As Integer = 0


Dim auxDato As String 


  If Not gridDeDatos.ItemsSource is Nothing then 
    lstAux =  gridDeDatos.ItemsSource 
  End If
       
 datos = CUtileria.ObtenerDatosClipboard (vblf ,vbTab)

'1) Validaciones: obtener información del portapapeles

   If datos.Datos.length = 0 then 
      Exit sub
   End If


  If datos is Nothing then 
     MessageBox.Show ("No se pudo copiar los datos") 
     gridDeDatos.CancelEdit (DataGridEditingUnit.Cell)         
     Exit Sub 
  End If

'2) Validaciones: compatibilidad  
  

  For i = 0 to datos.NumeroRenglones - 1 
      Try
                  
          auxDato = Convert.ToInt32 ( datos.Datos(i)(0).ToString.Trim)
          lstAux.Add (New CTInstrumentosValmerBatch( CTInstrumentosValmerBatch.TipoDeInstrumentoAProcesar.Dinamico,"",-1,auxDato,""))

      Catch ex As Exception
            nErrores += 1
      End Try           
  Next

  If nErrores > 0 then 
     If MessageBox.Show ("Existen " & nErrores  & " datos erróneos de " & datos.NumeroRenglones & ". ¿Desea pegar los datos correctos solamente?", "Copiado de No. de instrumentos",MessageBoxButton.YesNo,MessageBoxImage.Question) = MessageBoxResult.Yes then 
        gridDeDatos.ItemsSource = lstAux  
     End If

   Else
       gridDeDatos.ItemsSource = lstAux  
  End If

  gridDeDatos.Items.Refresh () 

End Sub

Private Sub grdNumInstrumento_MouseRightButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles grdNumInstrumento.MouseRightButtonUp
     grdNumInstrumento.ContextMenu =   AgregarMenuContextualInstrumento() 
  
End Sub

Private Sub grdNumInstrumento_PreparingCellForEdit(ByVal sender As System.Object , ByVal e As System.Windows.Controls.DataGridPreparingCellForEditEventArgs) Handles grdNumInstrumento.PreparingCellForEdit

   Dim instrumentos As ObservableCollection(Of CTInstrumentosValmerBatch ) = grdNumInstrumento.ItemsSource
           
   If instrumentos.Item(e.Row.GetIndex).Tipo <> -1  then 
      grdNumInstrumento.CancelEdit ()
   End If
     
End Sub

Private Sub imgRefreshGrupo_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgRefreshGrupo.MouseLeftButtonUp
Dim lstTipos As new ObservableCollection (Of CTInstrumentosValmerBatch)
 
 Mouse.OverrideCursor = Cursors.Wait     

 Try

   
  If not grdGrupo.ItemsSource is Nothing then 
    If grdGrupo.Items.Count > 0 then    
        lstTipos =   negocioValmer.ObtenerSecTypePorGrupo (grdGrupo.ItemsSource) 
        grdSecType.ItemsSource = lstTipos  
        grdSecType.UpdateLayout ()
    End If
  End If

Catch ex As Exception
            MessageBox.Show("Error TI500. Ocurrió el siguiente error: " & ex.Message, "Carga masiva Valmer", MessageBoxButton.OK, MessageBoxImage.Error)
End Try


 Mouse.OverrideCursor = Nothing 

End Sub

Private Sub imgRefreshSecType_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgRefreshSecType.MouseLeftButtonUp

Dim lstInstrumentos As new ObservableCollection (Of CTInstrumentosValmerBatch)

 
 Mouse.OverrideCursor = Cursors.Wait     

  If not grdSecType.ItemsSource is Nothing then 

    If grdSecType.Items.Count > 0 then
        lstInstrumentos =   negocioValmer.ObtenerInstrumPorSecType (grdSecType.ItemsSource) 
        grdNumInstrumento.ItemsSource = lstInstrumentos  
        grdNumInstrumento.UpdateLayout ()
    End If 

  End If

 Mouse.OverrideCursor = Nothing 

End Sub

Private Function  ObtenerCelda(ByRef miDataGrid As DataGrid, ByVal indexRow As Integer, ByVal indexCol As Integer  ) As DataGridCell 

Try
      Dim row as DataGridRow  = miDataGrid.ItemContainerGenerator.ContainerFromIndex(indexRow)            
      Dim cellContent As Object  = miDataGrid.Columns(indexCol).GetCellContent(row)     
 
      Dim objDepend As DependencyObject = cellContent
      Dim celda As DataGridCell = Nothing       

       While not objDepend is Nothing 

            If objDepend.GetType().Name = "DataGridCell" then 
               celda = objDepend           
               Return celda                                                      
            End If
           objDepend = VisualTreeHelper.GetParent (objDepend)   
      End While
Catch ex As Exception
    Throw ex
End Try

Return Nothing 
End Function

Private Sub imgGuardarInfo_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgGuardarInfo.MouseLeftButtonUp

 Dim sMsgError As String = ""
 Dim HayDatosAlmacenados As Boolean 
 Dim HayDatosParaDarDeAlta As Boolean  

  Try
     HayDatosAlmacenados = negocioValmer.HayDatosAlmacenadosParaLaMasiva () 
  Catch ex As Exception
            MessageBox.Show("Error TI500. Ocurrió un error al consultar la información, la información no ha podido ser almacenada." & ex.Message, "Carga masiva Valmer", MessageBoxButton.OK, MessageBoxImage.Error)
     Exit sub
  End Try
  
  If not Me.grdNumInstrumento.ItemsSource is Nothing  then      
    If Me.grdNumInstrumento.Items.Count > 0 then 
       HayDatosParaDarDeAlta = True 
     Else
       HayDatosParaDarDeAlta = False 
    End If
  else
     HayDatosParaDarDeAlta = False 
  End If


  If HayDatosAlmacenados = False and HayDatosParaDarDeAlta = False then 
      MessageBox.Show ("Los datos han sido almacenados exitosamente","Carga masiva",MessageBoxButton.OK,MessageBoxImage.None)
      Exit sub
  End If


  If HayDatosAlmacenados = False and HayDatosParaDarDeAlta = true  then
     If  negocioValmer.AlmacenarInstrumentosMasivos (Me.grdNumInstrumento.ItemsSource,sMsgError) = True then 
         MessageBox.Show ("Los datos han sido almacenados exitosamente","Carga masiva",MessageBoxButton.OK,MessageBoxImage.None)
     else
         MessageBox.Show ("No se pudo almacenar la información debido a: " & sMsgError,"Carga masiva",MessageBoxButton.OK,MessageBoxImage.Error)
     End If 
     Exit sub
  End If


  If HayDatosAlmacenados = true and HayDatosParaDarDeAlta = False then 
     if  MessageBox.Show("Existen datos almacenados, ¿esta seguro de sustituirlos? ","Carga masiva Valmer",MessageBoxButton.YesNo,MessageBoxImage.Question ) = MessageBoxResult.Yes then 
          If negocioValmer.EliminarDatosAlacenadosMasiva (sMsgError ) = False 
             MessageBox.Show ("Ocurrió un error al eliminar la información, la información no ha podido ser almacenada." & sMsgError  ,"Carga masiva Valmer",MessageBoxButton.OK,MessageBoxImage.Error)
             Exit sub
          End If
          MessageBox.Show ("Los datos han sido almacenados exitosamente","Carga masiva",MessageBoxButton.OK,MessageBoxImage.None) 
    End If
    Exit Sub 
  End If


  If HayDatosAlmacenados = true and HayDatosParaDarDeAlta = true then
     if  MessageBox.Show("Existen datos almacenados, ¿esta seguro de sustituirlos? ","Carga masiva Valmer",MessageBoxButton.YesNo,MessageBoxImage.Question ) = MessageBoxResult.Yes then 
          If negocioValmer.EliminarDatosAlacenadosMasiva (sMsgError ) = False 
             MessageBox.Show ("Ocurrió un error al eliminar la información, la información no ha podido ser almacenada." & sMsgError  ,"Carga masiva Valmer",MessageBoxButton.OK,MessageBoxImage.Error)
             Exit sub
          End If

          If  negocioValmer.AlmacenarInstrumentosMasivos (Me.grdNumInstrumento.ItemsSource,sMsgError) = True then 
              MessageBox.Show ("Los datos han sido almacenados exitosamente","Carga masiva",MessageBoxButton.OK,MessageBoxImage.None)
          else
              MessageBox.Show ("No se pudo almacenar la información debido a: " & sMsgError,"Carga masiva",MessageBoxButton.OK,MessageBoxImage.Error)
          End If 

      else
        Exit Sub 
     End If

  

  End If



End Sub

Private Sub imgGuardarParam_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgGuardarParam.MouseLeftButtonUp

   Dim parametros As CValmerServicio.paramMasiva 
   Dim sMsgError  As String = ""


    Mouse.OverrideCursor =  Cursors.Wait  

   If Me.chkEjecutarMasiva.IsChecked then 
      parametros.ejecutar = 1
   else
      parametros.ejecutar = 0
   End If
     
   parametros.sfechaeject =  Me.fechaEjec.SelectedDate.Value.ToString ("yyyy-MM-dd") & " " & _
                            If (Me.tiempoEjec.txtHora.Text.Trim.Equals (""),"00",Me.tiempoEjec.txtHora.Text)  & ":" & _
                            If (Me.tiempoEjec.txtMinuto.Text.Trim.Equals (""),"00",Me.tiempoEjec.txtMinuto.Text) & ":" &  _
                            "00"
   
   


   If negocioValmer.AlmacenarParametros (parametros,sMsgError) = True then 
       MessageBox.Show ("Los parámetros se han almacenado correctamente", "Carga masiva Valmer",MessageBoxButton.OK,MessageBoxImage.None) 
       MainWindow.paramEjecMasivaValmer = negocioValmer.ObtenerParamEjecMasiva ()  
   else
       MessageBox.Show ("Los parámetros no han sido guardados debido a: " & smsgerror, "Carga masiva Valmer",MessageBoxButton.OK,MessageBoxImage.Error) 
   End If
     
 Mouse.OverrideCursor =  nothing 


End Sub

Private Sub imgMostrarInfo_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgMostrarInfo.MouseLeftButtonUp

   Dim lstInstrumAlmacenados As ObservableCollection(Of CTInstrumentosValmerBatch )


     Try
        lstInstrumAlmacenados = negocioValmer.ObtenerNumInstrumAlmacenados () 
     Catch ex As Exception
            MessageBox.Show("Error TI500. Ocurrió un error al intentar obtener los datos almacenados." & ex.Message, "Carga masiva Valmer", MessageBoxButton.OK, MessageBoxImage.Error)
        Exit Sub 
     End Try


     Me.grdNumInstrumento.ItemsSource = lstInstrumAlmacenados  
     Me.grdGrupo.ItemsSource = Nothing 
     Me.grdSecType.ItemsSource = Nothing 
  
     Me.grdNumInstrumento.UpdateLayout ()
     Me.grdGrupo.UpdateLayout ()
     Me.grdSecType.UpdateLayout 


End Sub

Private Sub CargarParametrosMasiva()
 Dim parametros As CValmerServicio.paramMasiva 
 parametros = negocioValmer.ObtenerParamEjecMasiva ()

 Me.chkEjecutarMasiva.IsChecked =  parametros.ejecutar     
 Me.fechaEjec.SelectedDate = parametros.fechaeject   

 Me.tiempoEjec.txtHora.Text =  parametros.fechaeject.Hour.ToString ("0#")   
 Me.tiempoEjec.txtMinuto.Text   = parametros.fechaeject.Minute.ToString ("0#")   
 Me.tiempoEjec.txtSegundo.Text   = "00"
  
End Sub

Private Sub imgCargaDecalogNumInstos_MouseLeftButtonUp_1(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgCargaDecalogNumInstos.MouseLeftButtonUp

 Dim thProc As System.Threading.Thread    
               
               
 Try           
        
          If CValmerServicio.EjecucionMasiva = False  then   
                MainWindow.lstDatosMasivosValmer.Clear ()
                For Each instrum As CTInstrumentosValmerBatch In grdNumInstrumento.ItemsSource 
                    MainWindow.lstDatosMasivosValmer.Add (New CTInstrumentosValmerBatch (instrum ))
                Next

               thProc = New System.Threading.Thread (AddressOf EjecutarMasiva)
               thProc .Start ()
          Else
                MessageBox.Show("Ya existe un proceso similar ejecutandose","Carga masiva Valmer",MessageBoxButton.OK,MessageBoxImage.Exclamation )            
          End If
                                                       

 Catch ex As Exception   
            MessageBox.Show("Error TI500. " & ex.Message)
 End Try
  
End Sub

private Sub EjecutarMasiva()
    Dim negocioValmetTh As New CValmerServicio ()
     Try
        negocioValmetTh.LanzarProcesamientoValmerBatch(MainWindow.lstDatosMasivosValmer)     
        negocioValmetTh.EjecutarProceso (True)
     Catch ex As Exception

     End Try
    
End Sub


'******************************************************BITACORA**************************************************************

 Private Sub CargarBitacora()
        Dim negocioLiq As New CLiquidezServicio()
        Dim sFechaIni As String 
        Dim sFechaFin As String 

        Try        

          sFechaIni =   String.Format(Me.fechaInicio.Text,"yyyy-MM-dd") & " " & String.Format ( Me.tiempoInicio.HoraCompleta ,"HH:mm:ss")
          sFechaFin  =  String.Format(Me.fechaFin.Text,"yyyy-MM-dd") & " " & String.Format ( Me.tiempoFin.HoraCompleta ,"HH:mm:ss")
            
          Me.grdDatosBit.ItemsSource = negocioValmer.ObtenerRegistrosBitacoraBatch(Convert.ToDateTime(sFechaIni), Convert.ToDateTime ( sFechaFin),true)
                                             
          Me.grdDatosBit.UpdateLayout ()
            
        Catch ex As Exception
            MessageBox.Show("Error TI500. No existe información para los criterios introducidos:" & ex.Message, "Carga de bitácora Valmer", MessageBoxButton.OK, MessageBoxImage.Exclamation)
        End Try

    End Sub
    
 Private Sub InicializarFechaHora () 

        Me.fechaInicio.Text = Date.Now.ToString ("dd/MM/yyyy") 
        Me.tiempoInicio.txtHora.Text  = "00"
        Me.tiempoInicio.txtMinuto.Text = "00" 
        Me.tiempoInicio.txtSegundo.Text = "00" 

        Me.fechaFin.Text = Now.ToString ("dd/MM/yyyy") 
        Me.tiempoFin.txtHora.Text  = Date.Now.Hour.ToString("0#")   
        Me.tiempoFin.txtMinuto.Text = Date.Now.Minute.ToString ("0#") 
        Me.tiempoFin.txtSegundo.Text = "00" 


    End Sub


Private Sub imgConsultar_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgConsultar.MouseLeftButtonUp
         CargarBitacora()
End Sub

Private Sub imgLimpiar_MouseLeftButtonUp(ByVal sender As System.Object , ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles imgLimpiar.MouseLeftButtonUp
       InicializarFechaHora () 
End Sub










End Class
